<script setup lang='ts'>
import { onMounted, ref } from 'vue';
import {useRouter} from 'vue-router';
import { userCollect,userLike } from "../api/api";
const router = useRouter()
const userCollectNum = ref(0)
const LikeNum = ref(0)
onMounted(()=>{
    collect()
    Like()
})
//初始化收藏
const collect = async() => {
    const res = await userCollect({mail:localStorage.getItem('mail') as string})
    if(res.data.code !== '200') return
    userCollectNum.value = res.data.data.length
}
//初始化收藏
const Like = async() => {
    const res = await userLike({mail:localStorage.getItem('mail') as string})
    if(res.data.code !== '200') return
    LikeNum.value = res.data.data.length
}
//切换收藏和喜欢页面
const userData = (e:string) => {
    router.push({name:'userData',query:{title:e}})
}
//购买次数跳转
const BuyData = () => {
    router.push({name:'Buy',query:{title:'购买次数',isrouter:3}})
}
</script>

<template>
    <van-cell title="我的收藏" :value="userCollectNum" is-link @click="userData('我的收藏')"/>
    <van-cell title="我的喜欢" :value="LikeNum" is-link @click="userData('我的喜欢')"/>
    <van-cell title="购买次数" is-link @click="BuyData"/>
    <van-cell title="联系我们" is-link @click=""/>
</template>

<style scoped></style>